#include "QuestionAdder.h"
#include "AssetPool.h"
#include "..\core\src\AssetManager.h"

namespace Xps
{
	QuestionAdder::QuestionAdder(QWidget* parent) : AssetAdder(parent, "Add Question", ":/rs/images/question.png")
	{
		content = setupContent();
	}

	QuestionAdder::~QuestionAdder(void)
	{
	}

	QWidget* QuestionAdder::setupContent()
	{
		QHBoxLayout* box = new QHBoxLayout();
		QGridLayout* content_layout = new QGridLayout();
		
		onechoice = new QRadioButton("One Choice");
		multichoice = new QRadioButton("Multiple Choice");
		text = new QLineEdit();

		content->setLayout(content_layout);
		content->setStyleSheet("background: white; color: black;");
		content_layout->addWidget(text, 1, 0);
		content_layout->addWidget(new QLabel("Insert Question here:"),0, 0);
		onechoice->setChecked(true);
		box->addWidget(onechoice);
		box->addWidget(multichoice);
		box->insertStretch(2,100);
		content_layout->addLayout(box, 2, 0);
		text->setFocus(Qt::FocusReason::TabFocusReason);

		return content;
	}


	void QuestionAdder::accept()
	{
		XpsAssets::AssetManager* am = ((Xps::AssetPool*) parent())->am;
		int id = am->createQuestion();
		XpsAssets::IQuestion* q = am->getQuestion(id);
		q->setText(text->text());
		q->setChoiceMode(onechoice->isChecked() ? 0 : 1);
		QDialog::accept();
	}
}
